<template>
  <div class="updateGenderWrap">
    <van-picker
      title="标题"
      show-toolbar
      :columns="columns"
      :default-index="defaultIndex"
      @confirm="onConfirm"
      @cancel="$emit('onCancel')"
    />
  </div>
</template>
<script>
import { changeUserProfile } from '../../../api/profile'
export default {
  name: 'UpdateGender',
  components: {},
  data () {
    return {
      columns: ['女', '男'],
      defaultIndex: this.value// 默认值
    }
  },
  props: {
    value: {
      type: Number,
      required: true
    }
  },
  methods: {
    // 确认
    async onConfirm (value, index) {
    //   Toast(`当前值：${value}, 当前索引：${index}`)
      const params = {
        gender: index
      }
      await changeUserProfile(params)
      this.$emit('input', index)
      this.$emit('onCancel')
      this.$toast.success('修改成功')
    }

  }
}
</script>
<style scoped>
</style>
